package xcmg.device.web.logistic;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xcmg.device.infra.BasicController;
import xcmg.device.infra.ErrorCode;
import xcmg.device.service.crm.util.ActionResultUtil;
import xcmg.device.service.logistic.LogisticWayBillService;
import xcmg.device.service.vo.logistic.*;
import yb.ecp.fast.infra.annotation.FastMappingInfo;
import yb.ecp.fast.infra.infra.ActionResult;
import yb.ecp.fast.infra.infra.PageCommonVO;
import yb.ecp.fast.infra.infra.SearchCommonVO;

import java.util.List;

/**
 * @Des 物流状态controller
 * @Date 2021/5/24 10:06
 * @Author wangzhaoyu
 * @Param
 * @Return
 */
@RestController
@RequestMapping("/logisticStatus")
public class LogisticStatusController extends BasicController {

    @Autowired
    private LogisticWayBillService logisticWayBillService;
    /**
     * @Des 物流状态列表
     * @Date 2021/5/24 10:07
     * @Author wangzhaoyu
     * @Param []
     * @Return yb.ecp.fast.infra.infra.ActionResult
     */
    @PostMapping("/logisticListing")
    @FastMappingInfo(needLogin = true)
    public ActionResult logisticListing(@RequestBody SearchCommonVO<LogisticWayBillListQueryParamVO> condition) throws Exception {
        String orgId = getOrgId();
        PageCommonVO<LogisticStatusListingWaybillVO> result = logisticWayBillService.logisticStatusListingWaybills(orgId,condition);
        return ActionResultUtil.successActionResult(result.getPageInfo());
    }

    /**
     * @Des 物流信息录入
     * @Date 2021/5/24 20:46
     * @Author wangzhaoyu
     * @Param [enterVO]
     * @Return yb.ecp.fast.infra.infra.ActionResult
     */
    @PostMapping("/logisticRecordEnter")
    @FastMappingInfo(needLogin = true)
    public ActionResult logisticRecordEnter(@RequestBody LogisticNodeRecordEnterVO enterVO) throws Exception {
        String userId = getUserId();
        String userName = getUserName();
        logisticWayBillService.saveLogisticRecord(userId,userName,enterVO);
        return ActionResultUtil.successActionResult();
    }

    /**
     * @Des 物流运单的物流信息
     * @Date 2021/5/25 13:54
     * @Author wangzhaoyu
     * @Param []
     * @Return yb.ecp.fast.infra.infra.ActionResult
     */
    @GetMapping("/logisticRecords")
    @FastMappingInfo(needLogin = true)
    public ActionResult logisticRecords(String wayBillId){
        List<LogisticNodeRecordVO> result = logisticWayBillService.getLogisticRecords(wayBillId);
        return ActionResultUtil.successActionResult(result);
    }

    /**
     * @Des 物流运单到货确认接口
     * @Date 2021/5/25 15:34
     * @Author wangzhaoyu
     * @Param [arrivalConfirm]
     * @Return yb.ecp.fast.infra.infra.ActionResult
     */
    @PostMapping("/arrivalConfirm")
    @FastMappingInfo(needLogin = true)
    public ActionResult arrivalConfirm(@RequestBody LogisticWaybillArrivalConfirmVO arrivalConfirm) throws Exception {
        String userId = getUserId();
        String userName = getUserName();
        logisticWayBillService.arrivalConfirm(userId,userName,arrivalConfirm);
        return ActionResultUtil.successActionResult();
    }

    /**
     * @Des 物流运单签收
     * @Date 2021/5/25 17:10
     * @Author wangzhaoyu
     * @Param [wayBillId]
     * @Return yb.ecp.fast.infra.infra.ActionResult
     */
    @GetMapping("/signConfirm")
    @FastMappingInfo(needLogin = true)
    public ActionResult signConfirm(String wayBillId) throws Exception {
        if(StringUtils.isEmpty(wayBillId)){
            return ActionResultUtil.errorActionResult(ErrorCode.IllegalArument);
        }
        String userId = getUserId();
        String userName = getUserName();
        logisticWayBillService.signConfirm(userId,userName,wayBillId);
        return ActionResultUtil.successActionResult();
    }

    /**
     * @Des 物流状态看板
     * @Date 2021/5/27 14:23
     * @Author wangzhaoyu
     * @Param []
     * @Return yb.ecp.fast.infra.infra.ActionResult
     */
    @GetMapping("/logisticStatusDisplayBoard")
    @FastMappingInfo(needLogin = true)
    public ActionResult logisticStatusDisplayBoard(Integer pageSize,Integer pageNum) throws Exception {
        String orgId = getOrgId();
        PageCommonVO<LogisticStatusDisplayBoardVO> result = logisticWayBillService.logisticStatusDisplayBoard(orgId,pageSize,pageNum);
        return ActionResultUtil.successActionResult(result);
    }

    /**
     * @Des 同步物流信息
     * @Date 2021/5/28 16:03
     * @Author wangzhaoyu
     * @Param [wayBillId]
     * @Return yb.ecp.fast.infra.infra.ActionResult
     */
    @GetMapping("/synLogisticInfo")
    @FastMappingInfo(needLogin = true)
    public ActionResult synLogisticInfo(String wayBillId) throws Exception {
        ActionResult result = logisticWayBillService.synLogisticInfo(wayBillId);
        return result;
    }
}
